Skip to content

Conversation

matthias-springer
Copy link
Member

Erasing/replacing an op, which is also the current insertion point, invalidates the insertion point. Explicitly set the insertion point, so that subsequent op insertions do not crash after the One-Shot Dialect Conversion refactoring. (ConversionPatternRewriter will start behaving more like a "normal" rewriter.)

Erasing/replacing an op, which is also the current insertion point, invalidates the insertion point. Explicitly set the insertion point, so that copy does not crash after the One-Shot Dialect Conversion refactoring. (ConversionPatternRewriter will start behaving more like a "normal" rewriter.)
@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-linalg

Author: Matthias Springer (matthias-springer)

Changes

Erasing/replacing an op, which is also the current insertion point, invalidates the insertion point. Explicitly set the insertion point, so that subsequent op insertions do not crash after the One-Shot Dialect Conversion refactoring. (ConversionPatternRewriter will start behaving more like a "normal" rewriter.)


Full diff: https://github.com/llvm/llvm-project/pull/146908.diff

1 Files Affected:

  • (modified) mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp (+1)
diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp
index c460a8bb2f4b2..ca8f6fcb1e122 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp
@@ -815,6 +815,7 @@ class MaxPool2dConverter : public OpConversionPattern<tosa::MaxPool2dOp> {
         ValueRange{paddedInput, fakeWindowDims}, filledEmptyTensor, strideAttr,
         dilationAttr);
 
+    rewriter.setInsertionPointAfter(op);
     rewriter.replaceOp(op, resultOp);
 
     // NaN propagation has no meaning for non floating point types.

@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2025

@llvm/pr-subscribers-mlir-tosa

Author: Matthias Springer (matthias-springer)

Changes

Erasing/replacing an op, which is also the current insertion point, invalidates the insertion point. Explicitly set the insertion point, so that subsequent op insertions do not crash after the One-Shot Dialect Conversion refactoring. (ConversionPatternRewriter will start behaving more like a "normal" rewriter.)


Full diff: https://github.com/llvm/llvm-project/pull/146908.diff

1 Files Affected:

  • (modified) mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp (+1)
diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp
index c460a8bb2f4b2..ca8f6fcb1e122 100644
--- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp
+++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp
@@ -815,6 +815,7 @@ class MaxPool2dConverter : public OpConversionPattern<tosa::MaxPool2dOp> {
         ValueRange{paddedInput, fakeWindowDims}, filledEmptyTensor, strideAttr,
         dilationAttr);
 
+    rewriter.setInsertionPointAfter(op);
     rewriter.replaceOp(op, resultOp);
 
     // NaN propagation has no meaning for non floating point types.

@zero9178
Copy link
Member

zero9178 commented Jul 3, 2025

I am curious, do you think it'd be feasible for erase op (and replace op) to accommodate for the insertion point being erased? Eg move the insertion point to the next op if the current is being removed.

@matthias-springer
Copy link
Member Author

I tried this here but it makes op erasure more expensive. What do you think?

@banach-space
Copy link
Contributor

Thanks for the fix!

I tried this #146955 but it makes op erasure more expensive. What do you think?

Personally I feel that updating the insertion point should remain the responsibility of the user. Looking at this specific example, it feels like ewriter.replaceOp(op, resultOp); is invoked pre-maturely.

This is just an opinion, I don't have any data for or against a particular approach.

@matthias-springer matthias-springer merged commit b293c8b into main Jul 11, 2025
13 checks passed
@matthias-springer matthias-springer deleted the users/matthias-springer/tosa_ip branch July 11, 2025 11:46
zero9178 added a commit that referenced this pull request Oct 3, 2025
These insertion points were added in
#146551 and
#146908 to support the one-shot
dialect conversion driver which performs changes to the IR immediately
and would otherwise invalidate previous insertion points.

Since then, the insertion point has been made resilient against op
erasure (#146955) making the
changes now redundant.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 3, 2025
…837)

These insertion points were added in
llvm/llvm-project#146551 and
llvm/llvm-project#146908 to support the one-shot
dialect conversion driver which performs changes to the IR immediately
and would otherwise invalidate previous insertion points.

Since then, the insertion point has been made resilient against op
erasure (llvm/llvm-project#146955) making the
changes now redundant.
MixedMatched pushed a commit to MixedMatched/llvm-project that referenced this pull request Oct 3, 2025
These insertion points were added in
llvm#146551 and
llvm#146908 to support the one-shot
dialect conversion driver which performs changes to the IR immediately
and would otherwise invalidate previous insertion points.

Since then, the insertion point has been made resilient against op
erasure (llvm#146955) making the
changes now redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants